
<template>
  <el-dialog
    title="提示"
    :visible="showCheckDialog"
    width="30%"
    center
    @close="btnCancle"
  >
    <el-form
      :model="chkFromData"
      :rules="rules"
      ref="roleForm"
    >
      <el-form-item prop="radio">
        <el-radio
          v-model="chkFromData.chkState"
          label="1"
        >通过</el-radio>
        <el-radio
          v-model="chkFromData.chkState"
          label="2"
        >拒绝</el-radio>
      </el-form-item>
      <el-form-item prop="chkRemarks">
        <el-input
          type="textarea"
          v-model="chkFromData.chkRemarks"
          placeholder="请输入审核意见"
          :rows="2"
        >
        </el-input>
      </el-form-item>
    </el-form>

    <span
      slot="footer"
      class="dialog-footer"
    >
      <el-button @click="btnCancle">取 消</el-button>
      <el-button
        type="primary"
        @click="btnOk"
      >确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'

export default {
  // 组件名称
  // 审核的弹出层
  name: 'queChoCheckDialog',
  props: {
    showCheckDialog: {
      type: Boolean,
      required: true
    },
    // 所要审核的题目的id
    preSubjectId: {
      type: [String, Number],
      default: null
    }
  },
  // 组件状态值
  data () {
    return {

      // chkState: '',
      chkFromData: {
        chkState: '1',
        chkRemarks: ''
      },
      rules: {
        chkRemarks: [
          { required: true, message: '请输入审核意见', trigger: 'blur' },
          { min: 1, max: 100, message: '长度在1~100之间', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    btnCancle () {
      this.$emit('update:showCheckDialog', false)
    },
    // 试题审核
    async btnOk () {
      try {
        // 发送请求
        await choiceCheck({
          id: this.preSubjectId,
          chkState: this.chkFromData.chkState - 1 + 1,
          chkRemarks: this.chkFromData.chkRemarks.toString()
        })
        // 清空验证和表单
        this.chkFromData = {
          chkState: '1',
          chkRemarks: ''
        }
        this.$refs.roleForm.resetFields()
        // this.showCheckDialog = false
        this.$emit('update:showCheckDialog', false)
      } catch (err) {
        console.log(err)
      }
    }
  }
}
</script>

<style scoped lang="scss">
.check {
  line-height: 50px;
}
</style>
